package com.nineclock.sign.controller;
import com.nineclock.sign.dto.SignAllUserDTO;
import com.nineclock.sign.service.SignService;
import com.nineclock.common.entity.Result;
import com.nineclock.sign.dto.SignDTO;
import com.nineclock.sign.SignControllerApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.nineclock.common.entity.PageResult;
import com.nineclock.sign.dto.SignPCListDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;


import java.io.IOException;

@RestController
@RequestMapping
public class SignController implements SignControllerApi {

    @Autowired
    SignService signService;

    @Override
    @PostMapping("/insert")
    public Result sign(SignDTO signDTO) {

        signService.sign(signDTO);
        return Result.success();
    }


    //获取当前用户当天签到次数
    @Override
    @GetMapping("/getDayCount")
    public Result getDayCount() {
        Integer count = signService.getDayCount();
        return Result.success(count);
    }


    //查询当前员工本月签到记录
    @Override
    @GetMapping("/pagingSignCurrentUserByMonth")
    public Result<List<SignDTO>> pagingSignCurrentUserByMonth(String dateStr) {
        List<SignDTO> signDTOList = signService.pagingSignCurrentUserByMonth(dateStr);
        return Result.success(signDTOList);
    }

    //查看所有员工指定日期签到列表
    @Override
    @GetMapping("/listSignAllUser")
    public Result<List<SignAllUserDTO>> listSignAllUser(String dateStr) {
        List<SignAllUserDTO> signAllUserDTOList = signService.listSignAllUser(dateStr);
        return Result.success(signAllUserDTOList);
    }

    /**
     * 查询当前企业用户签到信息列表
     *
     * @return
     */
    @Override
    @GetMapping("/sign")
    public Result<PageResult<SignPCListDTO>> querySignPCListPage(

            @RequestParam(value = "page", required = false) Integer page,
            @RequestParam(value = "pageSize", required = false) Integer pageSize,
            @RequestParam("startTime")String startTime,
            @RequestParam("endTime")String endTime) {
        PageResult<SignPCListDTO> signPCListDTOS = signService.querySignPCListPage(page,pageSize,startTime,endTime);
        return Result.success(signPCListDTOS);
    }

    @Override
    @GetMapping("/export")
    public void exportSignData(String startTime, String endTime) throws IOException {
        signService.exportSignData(startTime,endTime);
    }


}

